﻿<Window x:Class="OrderManager.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="订单管理工具" Height="500" Width="800" Loaded="Window_Loaded">
    <Window.Resources>
        <Style x:Key="OrderDataGridStyle" TargetType="{x:Type DataGrid}">
            <Setter Property="AutoGenerateColumns" Value="false"/>
            <Setter Property="CanUserAddRows" Value="false"/>
            <Setter Property="CanUserDeleteRows" Value="false"/>
            <Setter Property="CanUserReorderColumns" Value="false"/>
            <Setter Property="CanUserResizeRows" Value="false"/>
            <Setter Property="IsReadOnly" Value="true"/>
            <Setter Property="RowDetailsVisibilityMode" Value="VisibleWhenSelected"/>
            <Setter Property="RowHeight" Value="18"/>
            <Setter Property="SelectionMode" Value="Extended"/>
            <Setter Property="SelectionUnit" Value="CellOrRowHeader"/>
            <Setter Property="RowHeaderStyle">
                <Setter.Value>
                    <Style TargetType="{x:Type DataGridRowHeader}">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate>
                                    <StackPanel Orientation="Horizontal" Background="LightGray"  HorizontalAlignment="Right">
                                        <TextBlock Text="{Binding Expander}" VerticalAlignment="Center" HorizontalAlignment="Center"></TextBlock>
                                        <Image Source="{Binding Flag}" Stretch="Fill" Width="16" Height="16" VerticalAlignment="Center" HorizontalAlignment="Center"/>
                                    </StackPanel>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </Setter.Value>
            </Setter>

            <Setter Property="RowDetailsTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <ListBox Visibility="{Binding RowDetailVisibility}" ItemsSource="{Binding Order.AllItems}">
                            <ListBox.ItemContainerStyle>
                                <Style TargetType="ListBoxItem">
                                    <Setter Property="Template">
                                        <Setter.Value>
                                            <ControlTemplate TargetType="ListBoxItem">
                                                <Border BorderBrush="LightBlue" BorderThickness="3">
                                                    <StackPanel Orientation="Horizontal">
                                                        <TextBlock Margin="3" Text="{Binding Name}"/>
                                                        <TextBlock Margin="3" Text="{Binding Color}"/>
                                                        <TextBlock Margin="3" Text="{Binding Size}"/>
                                                        <TextBlock Margin="3" Text="{Binding Money}"/>
                                                    </StackPanel>
                                                </Border>
                                            </ControlTemplate>
                                        </Setter.Value>
                                    </Setter>
                                </Style>
                            </ListBox.ItemContainerStyle>
                            <ListBox.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <WrapPanel/>
                                </ItemsPanelTemplate>
                            </ListBox.ItemsPanel>
                        </ListBox>
                    </DataTemplate>
                </Setter.Value>
            </Setter>

            <Setter Property="RowStyle">
                <Setter.Value>
                    <Style TargetType="{x:Type DataGridRow}">
                        <Setter Property="Background" Value="{Binding Background}"/>
                    </Style>
                </Setter.Value>
            </Setter>

        </Style>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="3*"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="1*"/>
        </Grid.RowDefinitions>

        <GroupBox Header="选择商铺" Grid.Row="0" Margin="3" MinHeight="40">
            <ListBox MinHeight="30" 
                                     Name="lstShops" 
                                     ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
                                     ScrollViewer.VerticalScrollBarVisibility="Disabled" 
                                     SelectionMode="Extended" >
                <ListBox.ItemContainerStyle>
                    <Style TargetType="ListBoxItem">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="ListBoxItem">
                                    <StackPanel Orientation="Horizontal" Margin="3,0,0,0">
                                        <CheckBox IsChecked="{Binding Path=Checked}" Margin="3" VerticalAlignment="Center"/>
                                        <TextBlock Text="{Binding OrderManager.Type}" Margin="3" VerticalAlignment="Center"/>
                                        <TextBlock Text="-" Margin="3" VerticalAlignment="Center"/>
                                        <TextBlock Text="{Binding OrderManager.ShopName}" Margin="3" VerticalAlignment="Center"/>
                                    </StackPanel>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </ListBox.ItemContainerStyle>
                <ListBox.ItemsPanel>
                    <ItemsPanelTemplate>
                        <WrapPanel/>
                    </ItemsPanelTemplate>
                </ListBox.ItemsPanel>
            </ListBox>
        </GroupBox>

        <GroupBox Header="操作选择" Grid.Row="1" Margin="3">
            <StackPanel Orientation="Horizontal" >
                <TextBlock Text="订单状态" Margin="3" VerticalAlignment="Center"/>
                <ComboBox Name="cbbOrderState" Margin="3" Width="110">
                    <ComboBoxItem>货到付款待发货</ComboBoxItem>
                    <ComboBox.SelectedIndex>0</ComboBox.SelectedIndex>
                </ComboBox>
                <TextBlock Text="旗帜颜色" Margin="3" VerticalAlignment="Center"></TextBlock>
                <ComboBox Name="cbbFlags" Margin="3" Width="50">
                    <ComboBoxItem>全部</ComboBoxItem>
                    <ComboBoxItem>无色</ComboBoxItem>
                    <ComboBoxItem>红色</ComboBoxItem>
                    <ComboBox.SelectedIndex>1</ComboBox.SelectedIndex>
                </ComboBox>
                <Button Name="btnDownload" Margin="3" VerticalAlignment="Center" Content="下载" Width="60" Click="btnDownload_Click"/>
                <CheckBox Name="chkCheckInNonSelectedShop" IsChecked="True" Margin="3" VerticalAlignment="Center" Content="在没有选择的商铺中检查订单"/>
                <CheckBox Name="chkChecnInHistory" IsChecked="False" Margin="3" VerticalAlignment="Center" Content="检查历史订单"/>
                <Button Name="btnCheckAlreadyExist" Width="60" Content="检查订单" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="3" Click="btnCheckAlreadyExist_Click"/>
                <Button Name="btnRefresh" Width="60" Content="刷新" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="3" Click="btnRefresh_Click"/>
            </StackPanel>
        </GroupBox>

        <GroupBox Header="颜色提示" Grid.Row="2" Margin="3">
            <StackPanel Orientation="Horizontal">
                <Ellipse Width="20" Height="20" Fill="Red" Margin="3" />
                <TextBlock Text="拒收或者退货" Margin="3" VerticalAlignment="Center"/>
                <Ellipse Width="20" Height="20" Fill="Yellow" Margin="3" />
                <TextBlock Text="重复下单" Margin="3" VerticalAlignment="Center"/>
                <Ellipse Width="20" Height="20" Fill="Blue" Margin="3" />
                <TextBlock Text="地址含村" Margin="3" VerticalAlignment="Center"/>
                <TextBlock Text="双击可以备注订单" Margin="30,3" FontSize="16" VerticalAlignment="Center" Foreground="Red"/>
            </StackPanel>
        </GroupBox>

        <GroupBox Header="订单数据" Grid.Row="3" Margin="3">
            <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
                <DataGrid Name="dgvOrders" Margin="3" Style="{StaticResource ResourceKey=OrderDataGridStyle}" AutoGenerateColumns="False" IsReadOnly="True">
                    <DataGrid.ContextMenu>
                        <ContextMenu >
                            <MenuItem Header="标记为 圆到" Name="miYTArrive" Click="miYTArrive_Click"/>
                            <MenuItem Header="标记为 宅到" Name="miZhaiArrive" Click="miZhaiArrive_Click"/>
                            <MenuItem Header="标记为 不到" Name="noneArrvie" Click="noneArrvie_Click"/>
                            <MenuItem Header="启动手动标记" Name="startManualEdit" Click="startManualEdit_Click"/>
                        </ContextMenu>
                    </DataGrid.ContextMenu>

                    <DataGrid.Columns>
                        <DataGridTextColumn Header="商铺信息" Width="Auto" Binding="{Binding Order.ShopInfo}"/>
                        <DataGridTextColumn Header="用户编号" Width="Auto" Binding="{Binding Order.Name}"/>
                        <DataGridTextColumn Header="真实姓名" Width="Auto" Binding="{Binding Order.RealName}"/>
                        <DataGridTextColumn Header="购买信息" Width="Auto" Binding="{Binding Item}"/>
                        <DataGridTextColumn Header="下单时间" Width="Auto" Binding="{Binding Order.CreateTime}"/>
                        <DataGridTextColumn Header="联系方式" Width="Auto" Binding="{Binding Order.Phone}"/>
                        <DataGridTextColumn Header="收货地址" Width="Auto" Binding="{Binding Order.Address}"/>
                        <DataGridTextColumn Header="买家描述" Width="Auto" Binding="{Binding Order.BuyerComment}"/>
                        <DataGridTextColumn Header="卖家描述" Width="Auto" Binding="{Binding Order.SellerComment}"/>
                    </DataGrid.Columns>
                </DataGrid>
            </ScrollViewer>
        </GroupBox>

        <GridSplitter Grid.Row="4" Height="5" VerticalAlignment="Center" HorizontalAlignment="Stretch"/>

        <GroupBox Grid.Row="5" Header="历史订单">
            <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
                <DataGrid Name="dgvHistoryItem" Margin="3" Style="{StaticResource ResourceKey=OrderDataGridStyle}">
                    <DataGrid.Columns>
                        <DataGridTextColumn Header="商铺信息" Width="Auto" Binding="{Binding Order.ShopInfo}"/>
                        <DataGridTextColumn Header="用户编号" Width="Auto" Binding="{Binding Order.Name}"/>
                        <DataGridTextColumn Header="真实姓名" Width="Auto" Binding="{Binding Order.RealName}"/>
                        <DataGridTextColumn Header="购买信息" Width="Auto" Binding="{Binding Item}"/>
                        <DataGridTextColumn Header="下单时间" Width="Auto" Binding="{Binding Order.CreateTime}"/>
                        <DataGridTextColumn Header="联系方式" Width="Auto" Binding="{Binding Order.Phone}"/>
                        <DataGridTextColumn Header="收货地址" Width="Auto" Binding="{Binding Order.Address}"/>
                        <DataGridTextColumn Header="买家描述" Width="Auto" Binding="{Binding Order.BuyerComment}"/>
                        <DataGridTextColumn Header="卖家描述" Width="Auto" Binding="{Binding Order.SellerComment}"/>
                    </DataGrid.Columns>
                </DataGrid>
            </ScrollViewer>
        </GroupBox>

    </Grid>
</Window>
